package com.founder.android.parser;

/**
 * XML解析器解析结果包装类
 * @author chen_weihua
 *
 */
public class ParserWrapper implements Runnable {
	
	private ParserListener callbackActivity;
	
	private Throwable error;
	
	private Object data;
	
	private int messageType;
	
	public ParserWrapper(ParserListener callbackActivity) {
		this.callbackActivity = callbackActivity;
		messageType = -1;
	}

	@Override
	public void run() {
		if (messageType == 1) {
			callbackActivity.onParseBegin();
		} else if (messageType == 2) {
			callbackActivity.onParseItem(data);
		} else if (messageType == 3) {
			callbackActivity.onParseEnd();
		} else {
			callbackActivity.onParseFailed(error);
		}
	}

	public void setError(Throwable error) {
		messageType = -1;
		this.error = error;
	}
	
	public void setData(Object data) {
		messageType = 2;
		this.data = data;
	}
	
	public void setEnd() {
		messageType = 3;
	}
	
	public void setBegin() {
		messageType = 1;
	}

}
